import { ValidationPipe } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { NestFactory } from '@nestjs/core'
import { NestExpressApplication } from '@nestjs/platform-express'
import * as compression from 'compression'
import { AppModule } from './app.module'
import { CustomLogger } from './services/custom-logger'

async function bootstrap() {
    const app = await NestFactory.create<NestExpressApplication>(AppModule, { abortOnError: false })
    app.useLogger(app.get(CustomLogger))
    app.use(
        compression({
            filter: () => true,
            threshold: 0
        })
    )
    app.useBodyParser('json', { limit: '10mb' })
    app.useGlobalPipes(
        new ValidationPipe({
            errorHttpStatusCode: 400
        })
    )
    // 配置跨域选项
    app.enableCors({
        origin: true
    })

    const configService = app.get(ConfigService)

    const port = configService.get<number>('appPort')!

    await app.listen(port, '0.0.0.0')
}

bootstrap()
